package jp.design.patterns.factory.controller;

import jp.design.patterns.factory.factorys.SendFactory;
import jp.design.patterns.factory.interfac.ISender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * 发送端前端控制器
 *
 * @author: Jp
 * @date: 2022/9/15
 **/
@RestController
public class SenderController {


    /**
     *
     * 获取工厂创建的对象 (简单工厂模式)
     *
     *
     * @date: 2022/9/15
     */
    @GetMapping(value = "/v1/api/getSender/{type}")
    public void getSenderObject(@PathVariable("type") String type){

        SendFactory sendFactory = new SendFactory();
        // 发送短信
        ISender senderSms = sendFactory.produce("sms");
        senderSms.send();

        ISender senderEmail = sendFactory.produce("email");
        // 发送邮件
        senderEmail.send();

        ISender senderExpress = sendFactory.produce("express");
        // 发送快递
        senderExpress.send();

    }

    /**
     *
     * 获取工厂创建的对象 (多方法工厂模式)
     *
     *
     * @date: 2022/9/15
     */
    @GetMapping(value = "/v1/api/getSender")
    public void getSenderObject(){

        // 发送邮件
        SendFactory sendFactory = new SendFactory();
        ISender senderEmail = sendFactory.produceEmail();
        senderEmail.send();

        ISender senderSms = sendFactory.produceSms();
        // 发送短信
        senderSms.send();

        ISender senderExpress = sendFactory.produceExpress();
        // 发送快递
        senderExpress.send();

    }


}
